package com.atguigu.stgy.app.service.impl;

import com.atguigu.stgy.app.service.*;
import com.atguigu.stgy.model.entity.ApartmentInfo;
import com.atguigu.stgy.model.entity.FacilityInfo;
import com.atguigu.stgy.model.entity.GraphInfo;
import com.atguigu.stgy.model.entity.LabelInfo;
import com.atguigu.stgy.model.vo.ApartmentDetailVO;
import com.atguigu.stgy.model.vo.FeeValueVO;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.stgy.app.mapper.ApartmentInfoMapper;

import java.util.List;
//import com.atguigu.stgy.model.entity.ApartmentInfo;

@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo> implements ApartmentInfoService {
    @Resource
    ProvinceInfoService provinceInfoService;
    @Resource
    CityInfoService cityInfoService;
    @Resource
    DistrictInfoService districtInfoService;
    @Resource
    ApartmentFacilityService apartmentFacilityService;
    @Resource
    ApartmentLabelService apartmentLabelService;
    @Resource
    ApartmentFeeValueService apartmentFeeValueService;

    @Resource
    GraphInfoService graphInfoService;
    @Override
    public ApartmentDetailVO getDetailById(Long id) {
        //id查询公寓详情
        ApartmentInfo apartmentInfo = this.getById(id);
        //公寓id查询图片列表
        List<GraphInfo> graphInfos = graphInfoService.list(Wrappers.lambdaQuery(GraphInfo.class)
                .eq(GraphInfo::getItemId, id));
        //公寓id查询标签列表:  在中间表 apartment_label 中查询公寓的标签id列表  然后到标签表中查询标签列表
        List<LabelInfo> labelInfoList = apartmentLabelService.getLabelInfosByApartmentId(id);

        //公寓id查询配套列表:apartment_facility     facility_info
        List<FacilityInfo> facilityInfoList = apartmentFacilityService.getFacilityInfoByApartmentId(id);
        //公寓id查询杂费列表
        List<FeeValueVO> feeValueVoList = apartmentFeeValueService.getFeeValueVOsByApartmentId(id);

        //组装数据为ApartmentDetailVO对象
        ApartmentDetailVO apartmentDetailVO = new ApartmentDetailVO();
        BeanUtils.copyProperties(apartmentInfo , apartmentDetailVO);
        apartmentDetailVO.setGraphVoList(graphInfos);
        apartmentDetailVO.setLabelInfoList(labelInfoList);
        apartmentDetailVO.setFacilityInfoList(facilityInfoList);
        apartmentDetailVO.setFeeValueVoList(feeValueVoList);
        return apartmentDetailVO;
    }

}
